﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using com.hisun.iposm.net;

/// <summary>
/// NotifyHttpHandler 的摘要说明
/// </summary>
public class NotifyHttpHandler : IHttpHandler 
{
    public static log4net.ILog log = log4net.LogManager.GetLogger(typeof(NotifyHttpHandler));
    public NotifyHttpHandler()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region IHttpHandler 成员

    public bool IsReusable
    {
        get
        {
            return true;
        }
    }

    public void ProcessRequest(HttpContext context)
    {
        //后台接收支付结果通知
        NameValueCollection param = context.Request.Params;
        log.Info("recv a notify,param=" + param);
        MerchantPayResult res = null;
        try
        {
            res = HiSunTransEngine.payResult(param);
        }
        catch (Exception e1)
        {
            log.Error("接收后台通知出错！");
            log.Error(e1);
            return;
        }

        String sret = "";
        sret = sret + "amount=" + res.amount;
        sret = sret + "amtItem=" + res.amtItem;
        sret = sret + "&authorizeNo=" + res.authorizeNo;
        sret = sret + "&banks=" + res.banks;
        sret = sret + "&banks=" + res.contractName; 
        sret = sret + "&banks=" + res.invoiceTitle; 
        sret = sret + "&banks=" + res.message; 
        sret = sret + "&banks=" + res.mobile; 
        sret = sret + "&banks=" + res.orderId; 
        sret = sret + "&banks=" + res.payDate; 
        sret = sret + "&banks=" + res.payNo; 
        sret = sret + "&banks=" + res.reserved; 
        sret = sret + "&banks=" + res.returnCode; 
        sret = sret + "&banks=" + res.status;
        Console.Write("sret = " + sret);

        log.Info("通知结果：" + sret);
        context.Response.Write("SUCCESS");
    }

    #endregion
}
